# coding=utf-8
#================================================================
#   Copyright (C) 2020 * Ltd. All rights reserved.
#
#   File name   : selenium.py
#   Author      : ZouZheKang-1996
#   Created date: 2020-11-24 11:19:33
#   Description : XuQingQing,I really ❤ U！
#
#================================================================

from selenium import webdrive

wd = webdriver.Chrome(r'C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe')
wd.get('www.baidu.com')
wd.implicitly_wait(10)

#选择元素

ele = wd.find_element_by_id('kw')
ele = wd.find_element_by_name('a')
ele = wd.find_elements_by_tag_name('span')
ele = wd.find_elements_by_class_name('animal')
#根据css
ele = wd.find_elements_by_css_selector('div')
ele = wd.find_elements_by_css_selector('.plant')
ele = wd.find_elements_by_css_selector('#stext')
ele = wd.find_elements_by_css_selector('#stext>div')
ele = wd.find_elements_by_css_selector('#stext div')
ele = wd.find_elements_by_css_selector('h3+s')	//h3后面的s
ele = wd.find_elements_by_css_selector('h3~s')	//h3后面所有的s
ele = wd.find_elements_by_css_selector('[herf = a]')
ele = wd.find_elements_by_css_selector('.plant , .animal')
ele = wd.find_elements_by_tag_name('span :nth-child(x)')
ele = wd.find_elements_by_tag_name('span :nth-last-child(x)')
ele = wd.find_elements_by_tag_name('span :nth-of-type(x)')
ele = wd.find_elements_by_tag_name('span :nth-last-of-type(x)')
ele = wd.find_elements_by_tag_name('span :nth-child(odd)')
ele = wd.find_elements_by_tag_name('span :nth-child(even)')
#根据xpath
ele = wd.find_elements_by_xpath("/html/body/[@div='ok']")
ele = wd.find_elements_by_xpath("//[@div]")
ele = wd.find_elements_by_xpath("/html/body/div")
ele = wd.find_elements_by_xpath("//div//p")
ele = wd.find_elements_by_xpath("//div/*")
ele = wd.find_elements_by_xpath("//[@div='ok']/..")
ele = wd.find_elements_by_xpath("//div/*|//span/*")
ele = wd.find_elements_by_xpath("//div/span[x]")
ele = wd.find_elements_by_xpath("//div/span[last()-x]")

#输出

wd.title
wd.current_url
ele.text
ele.get_attribute('value')
ele.get_attribute('class')
ele.get_attribute('outerHTML')
ele.get_attribute('innerHTML')
wd.window_handles
wd.current_window_handle

#切换

wd.switch_to.frame('frame1')
wd.switch_to.default_content()
wd.switch_to.window(handle)

#弹窗

alert = wd.switch_to.alert
alert.accept()
alert.dismiss()
alert.text
alert.send_keys('xxx')

#其他

wd.get_window_size()
wd.set_window_size(x,y)
wd.get_screenshot_as_file('1.png') 	//截屏
